from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

class Modification(models.Model):
    author = models.ForeignKey(User)
    time = models.DateTimeField()
    url = models.URLField(blank=True, null=True)
    status = models.IntegerField()
    
    def __unicode__(self):
        return '%s %s %s' % (self.author,
                             self.time,
                             self.url)

class ModelModification(models.Model):
    modification = models.ForeignKey(Modification, related_name='models')
    content_type = models.ForeignKey(ContentType)
    content_object = generic.GenericForeignKey()
    object_id = models.PositiveIntegerField(blank=True, null=True, default=None)
    action = models.IntegerField() # add, modify, delete
    values = models.TextField() # serialized JSON kwpairs
    onaccept = models.CharField(max_length=100, null=True, blank=True)

    def __unicode__(self):
        return '%s %s %s' % (self.modification.author,
                             self.modification.time,
                             self.content_type.name)